package com.cat.greedyAlgorithm;

import java.util.Arrays;

/**
*   @description https://leetcode.cn/problems/largest-number/
*   @author 曲大人的喵
*   @create 2025/8/25 16:06
*   @since JDK17
*/

public class Solution35 {
    public String largestNumber(int[] nums) {
        int n = nums.length;
        String[] strs = new String[n];
        for (int i = 0; i < n; i++) {
            strs[i] = String.valueOf(nums[i]);
        }
        Arrays.sort(strs, (o1, o2) -> (o1 + o2).compareTo(o2 + o1));
        if (strs[0].equals("0")) {
            return "0";
        }
        StringBuilder ans = new StringBuilder();
        for (String s : strs) {
            ans.append(s);
        }
        return ans.toString();
    }
}
